import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';

class Test22 extends StatefulWidget{
    _TestState createState() => _TestState();
}

class _TestState extends State<Test22> {

    File imageFile;

  @override
  Widget build(BuildContext context) {

    return new Scaffold(
        appBar: AppBar(
            title: Text("底部弹窗选择"),
            centerTitle: true,
        ),
        body: Container(
            child: Column(
                children: <Widget>[
                    imageFile == null?
                    Container():
                    Container(
                        height: 400,
                        width: 300,
                        child: Image.file(
                            imageFile,
                            fit: BoxFit.fill,
                        ),
                    ),
                    FlatButton(
                        child: Text("打开底部弹窗选择"),
                        onPressed: (){
                            showModalBottomSheet(
                                context: context,
                                builder: (BuildContext context){
                                    return new Column(
                                        mainAxisSize: MainAxisSize.min,
                                        children: <Widget>[
                                            new ListTile(
                                                leading: new Icon(Icons.photo_camera),
                                                title: new Text("Camera"),
                                                onTap: () async {
                                                    imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
                                                    Navigator.pop(context);
                                                },
                                            ),
                                            new ListTile(
                                                leading: new Icon(Icons.photo_library),
                                                title: new Text("Gallery"),
                                                onTap: () async {
                                                    imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
                                                    Navigator.pop(context);
                                                },
                                            ),
                                        ],
                                    );
                                }
                            );
                        },
                    )
                ],
            ),
        ),
        
    );
  }


}
